package com.travelzen._15.generic;

import com.scofevil.util.Generator;

public class BasicGenerator<T> implements Generator<T> {

	private Class<T> type;

	public BasicGenerator(Class<T> type) {
		this.type = type;
	}

	@Override
	public T next() {
		try {
			return type.newInstance();
		} catch (InstantiationException | IllegalAccessException e) {
			throw new RuntimeException();
		}
	}

	public static <T> Generator<T> create(Class<T> type) {
		return new BasicGenerator<T>(type);
	}

	public static void main(String[] args) {
		BasicGenerator<Coffee> intG = new BasicGenerator<Coffee>(Coffee.class);
		Coffee i = intG.next();
		System.out.println(i);
	}
}
